package utils

import (
	"fmt"
	"time"
)

const DefaultDateTime = "1970-01-01 00:00:00"
const DefaultTimeLayout = "2006-01-02 15:04:05"

// DateNowString 获取当前时间 2022-03-31 14:05:12
func DateNowString() string {
	return time.Now().Format(DefaultTimeLayout)
}

// DateNowTime 获取当前时间戳 1648710442
func DateNowTime() int64 {
	return time.Now().Unix()
}

// TimestampToTime 将时间戳转换为时间
func TimestampToTime(timestamp int64) time.Time {
	return time.Unix(timestamp, 0)
}

// TimeToStamp 将时间转换为时间戳
func TimeToStamp(strTime string) (string, error) {
	t, err := time.Parse(DefaultTimeLayout, strTime)
	if err != nil {
		return "", err
	}
	fmt.Println("当前时间字符串转换为时间戳是", t.Unix())
	fmt.Println("当前时间戳是", time.Now().Unix())
	return t.String(), nil
}
